package com.nju.crawler.controller;

import com.nju.crawler.service.CrawlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;

/**
 * @authorliyunfei
 * @date2022/11/11
 **/
@ShellComponent
public class ShellController {

    @Autowired
    CrawlService crawlService;
    /***
     * 命令不支持小驼峰的写法--需提供stop接口
     * @param startIndex 爬取id的起始值
     * @param type 数据保存方式（file-only csv,db)
     * @param path 存储路径
     */
    @ShellMethod("crawl control.")
    public String start(Integer startIndex,String type,String path){
        System.out.println("start crawl at index "+startIndex);
        crawlService.singleCrawl(startIndex,path);
        System.out.println("take way of "+type);
        return "ok";
    }

    @ShellMethod("Add two integers together.")
    public int add(int a, int b) {
        return a + b;
    }

}
